package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet(name = "register",value = "/register")
public class Demo3_RegisterServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //设置一下字符编码
        request.setCharacterEncoding("UTF-8");

        //HttpServletRequest 类当中都能获取哪些关于 请求的信息

        //1.通过name属性获取页面的value值，这种方式是最常用的形式
//        String gender = request.getParameter("gender");
//        System.out.println(gender);

        //2.通过name属性获取页面的value值，用于一个名字有很多个值的情况 比如多选框
//        String[] projects = request.getParameterValues("project");
//        System.out.println(Arrays.toString(projects));

        //3.获取页面中所有的属性名
//        Enumeration<String> names = request.getParameterNames();
//        while(names.hasMoreElements()){
//            System.out.println(names.nextElement());
//        }

        //4.以键值对的形式返回页面的所有属性名和属性值
//        Map<String, String[]> parameterMap = request.getParameterMap();
//        Set<Map.Entry<String, String[]>> entries = parameterMap.entrySet();
//        for (Map.Entry<String, String[]> entry : entries) {
//            System.out.println(entry.getKey()+"====="+Arrays.toString(entry.getValue()));
//        }

        //5.获取请求头的所有的 key
//        Enumeration<String> headerNames = request.getHeaderNames();
//        while(headerNames.hasMoreElements()){
//            System.out.println(headerNames.nextElement());
//        }

        //6.获取请求头中的某个key的信息
//        String host = request.getHeader("host");
//        String agent = request.getHeader("user-agent");
//        System.out.println(host);
//        System.out.println(agent);


        //7.获取某些请求中的特定信息
//        String method = request.getMethod();
//        System.out.println("method:"+method);
//
//        String protocol = request.getProtocol();
//        System.out.println("protocol:"+protocol);
//
//        String requestURI = request.getRequestURI();
//        System.out.println("URI:"+requestURI);
//
//        StringBuffer requestURL = request.getRequestURL();
//        System.out.println("URL:"+requestURL);
//
//        String remoteAddr = request.getRemoteAddr();
//        System.out.println("addr:"+remoteAddr);


    }
}
